<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
	<meta name="layout" content="main">
</head>
<body>
	<div class="page-header">
		<h1>
			<g:message code="order.title" />
		</h1>
	</div>			

	<div id="divError" class="alert alert-error">
		<a class="close" data-dismiss="alert">×</a>
		<label id="lblError" ></label>
	</div>

	<div class="row">				 							 
		<div id="orderSummaryContainer" class="span6">				
			<h4> Datos del fotógrafo </h4>	
			<div class="form-horizontal">
						
				<div class="control-group">
					<label class="control-label" for="name"><g:message code="user.name" /></label>
					<div class="controls">
						<input type="text" id="txt_name" value="${purchaseOrderInstance.photographer}"  disabled>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label" for="phone"><g:message code="user.telephone" /></label>
					<div class="controls">
						<input type="text" id="txt_phone" value="${purchaseOrderInstance.photographer.telephone}" disabled>														
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label" for="mail"><g:message code="user.email" /></label>
					<div class="controls">
						<input type="text" id="txt_mail" value="${purchaseOrderInstance.photographer.email}" disabled>
													
					</div>
				</div>
																			
			</div>
		</div>
		
		<div id="orderSummaryContainer" class="span6">				
			<h4> <g:message code="cart.purchase.description" /> </h4>	
			<div class="form-horizontal">
						
				<div class="control-group">
					<label class="control-label" for="totalPhotos"><g:message code="cart.purchase.total.quantity" /></label>
					<div class="controls">
						<input type="text" id="txt_totalCopies" value="${purchaseOrderInstance.amountCopies}"  disabled>
					</div>
				</div>
				
				<div class="control-group">
					<label class="control-label" for="price"><g:message code="cart.purchase.total.price" /></label>
					<div class="controls">
						<input type="text" id="txt_orderPrice" value="${purchaseOrderInstance.price}" disabled>
													
					</div>
				</div>								
																			
			</div>
		</div>
	</div>
			
			<g:isOnline>
				<g:hasPaymentOnlineEnabled photographerId="${purchaseOrderInstance?.photographer?.id}">
					<h4 style="padding-top:30px;"> Modos de compra </h4>
					
					<ul>
						<li><strong> Solo encargo: </strong> El pedido quedará registrado y el fotógrafo se contactará para acordar la forma de pago </li>	
						<li><strong> Encargo y pago: </strong> El pedido será pagado a través de MercadoPago </li>
					</ul>				
				</g:hasPaymentOnlineEnabled>	
			</g:isOnline>												 
						
			<div class="row centered" style="padding-top:20px"> 
					<g:form name="orderForm" controller="purchaseOrder" action="completeConfirmation">		
						<g:hiddenField name="orderId" value="${purchaseOrderInstance.id}" />
					</g:form>
					
					<g:form name="deleteForm" controller="purchaseOrder" action="deleteOrder" >		
						<g:hiddenField name="orderId" value="${purchaseOrderInstance.id}"/>
					</g:form>
							
					<div class="btn-group">
						<!-- 
							<button id="btnDelete" class="btn btn-danger delete" data-toggle="modal" data-target="#deletePopup">
								<g:message code="order.discard" />
							</button>
						 -->

						<button id="btnOrder" class="btn btn-success " data-toggle="modal" data-target="#orderPopup">
							<g:message code="cart.order" />
						</button>
						
						<g:hasPaymentOnlineEnabled photographerId="${purchaseOrderInstance?.photographer?.id}">		
							<button id="btnOrderAndBuy" class="btn btn-success" data-toggle="modal" data-target="#orderAndBuyPopup">
								<g:message code="cart.payAndorder" />
							</button>
						</g:hasPaymentOnlineEnabled>
					</div>		
			</div>
																	
	<div class="separator"></div>
		
	<script type="text/javascript">
		jQuery(document).ready(function(){
			jQuery('#divError').hide();			
																							
			jQuery('#btn_deleteConfirm').click(function () {								
				jQuery('#deleteForm').submit();				
			});		

			jQuery('#btn_orderConfirm').click(function () {								
				jQuery('#orderForm').submit();
			});		

			$('#myModal').modal({ show: false})		

			var homeUrl = "${createLink(controller:'purchaseOrder', action: 'show', id:"${purchaseOrderInstance.id}")}";
			$('#btn_closeModal').click( function () {
				window.location.replace(homeUrl);
			});
				
	   	});

	</script>
		
	<g:render template="/common/informationPopup" model='[ msg:" "]'/>	
	<g:render template="/common/deleteConfirmationPopup" model='[button_text:"${message(code: 'order.discard')}", msg:"${message(code: 'order.discard.message')}", deleteConfirmButtonId:"btn_deleteConfirm", deleteModalId:"deletePopup"]'/> 
	<g:render template="/common/successConfirmationPopup" model='[button_text:"${message(code: 'cart.order')}", msg:"${message(code: 'cart.order.message')}", popup_id:"orderPopup", button_id:"btn_orderConfirm"]'/>
	<g:render template="/purchaseOrder/mpConfirmationPopup" model='[button_text:"${message(code: 'cart.payAndorder')}", msg:"${message(code: 'cart.orderAndPay.message')}", popup_id:"orderAndBuyPopup",checkoutUrl:"${checkoutUrl}",button_id:"btn_orderAndBuyConfirm"]'/>
	
	<g:isOnline>
		<g:hasPaymentOnlineEnabled photographerId="${purchaseOrderInstance?.photographer?.id}">
			
			<g:javascript src="mp.js" />		
			<script type="text/javascript">
				
				function execute_my_onreturn (json) {				
													
					var msg = undefined;
					if (json.collection_status=='approved'){
					  msg = "El pago ha sido acreditado";
					} else if(json.collection_status=='pending'){
					  msg = "El pago está siendo revisado";
					} else if(json.collection_status=='in_process'){    			   
					  msg = 'El pago está siendo revisado';
					} else if(json.collection_status=='rejected'){			  			 
					  msg = "El pago fué rechazado. Pruebe más adelante o con otra tarjeta";
					} 
					
					if (json.collection_status!=null){
						jQuery('#informationText').empty();
						jQuery('#informationText').append(msg);
						$('#informationModal').modal('show');
					}				
					//si es nulo se muestra mensaje de error.
					else{
						msg = "No se ha completado el proceso de pago";
						jQuery('#divError').show();
						jQuery('#lblError').empty();
						jQuery('#lblError').append(msg);
					}
					
					  
				}
				 
			</script>		
		</g:hasPaymentOnlineEnabled>
	</g:isOnline>
	
</body>
</html>